package com.hzhr.iot.device.controller;

import com.hzhr.iot.core.annotation.ApiImplicitInternalParams;
import com.hzhr.iot.core.annotation.Author;
import com.hzhr.iot.core.exception.ServiceException;
import com.hzhr.iot.device.controller.base.BaseController;
import com.hzhr.iot.device.model.pressureMonitor_code.PressureMonitor_CodeGetModel;
import com.hzhr.iot.device.model.pressureMonitor_code.PressureMonitor_CodePutModel;
import com.hzhr.iot.device.service.PressureMonitor_CodeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

@Api(tags = "PressureMonitor_Code", description = "压力监测仪的代码")
@RestController
@RequestMapping(value = "")
public class PressureMonitor_CodeController extends BaseController {
    @Autowired
    PressureMonitor_CodeService pressureMonitor_codeService;

    //region /pressure-monitors/{pressureMonitorId}/codes PUT
    //region swagger响应码 : putByPressureMonitorId
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功"),
    })
    //endregion
    //region swagger说明 : putByPressureMonitorId
    @ApiOperation(value="更新压力监测仪的设备代码", notes="更新压力监测仪的设备代码  \n简介 : 更新压力监测仪的设备代码  \n步骤 :  \n1. 查询压力监测仪 : (√)  \n 查询物联网设备(IOT_DEVICE)获取iotDevice_1，查询规则如下：  \n (1) iotDevice_1.id = 路径参数pressureMonitorId；  \n 如果iotDevice_1不存在，抛出异常201；  \n2. 验证新的设备代码的合法性 : (√)  \n 如果存在某个物联网设备(IOT_DEVICE)iotDeivce满足以下条件则抛出异常202：  \n (1) iotDeivce.code = body.code；  \n3. 更新压力监测仪信息 : (√)  \n 根据body更新iotDevice_1的相关信息；  \n 查询采集设备(COLLECT_DEVICE)获取collectDevice_1，  \n 如果collectDevice_1存在，更新collectDevice_1，更新规则如下：  \n (1) collectDevice_1.code = body.code；  \n4. 返回信息 : (√)  \n 调用“查询压力监测仪的设备代码”服务(device-service: /pressure-monitors/codes GET)获取result，调用规则如下：  \n (1) accessMode: GLOBAL；  \n (2) query: _equal_id = iotDevice_1.id；  \n 设置result属性，设置规则如下：  \n (1) result.changeCount = 更新数量；  \n 返回result；  \n",produces = "application/json")
    //endregion
    //region swagger参数 : putByPressureMonitorId
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token", value = "令牌",required = true, dataType = "string", paramType = "header"),

            @ApiImplicitParam(name = "show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    @ApiImplicitInternalParams({
            @ApiImplicitParam(name = "_token", value = "令牌",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-id", value = "用户编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-code", value = "用户代码",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-name", value = "用户名",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-company-id", value = "公司编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-dept-id", value = "部门编号",required = true, dataType = "int", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-user-type", value = "用户类型(关联: common_service.options.code, typeCode = 'USER_TYPE')",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-id", value = "交易流水号",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-transaction-type", value = "交易类型",required = true, dataType = "string", paramType = "header"),
            @ApiImplicitParam(name = "_hzhr-access-mode", value = "访问模式 0:一般 1:全局",defaultValue = "0", required = false, dataType = "int", paramType = "header"),

            @ApiImplicitParam(name = "_show", value = "展示形式 one:展示一个,list:展示列表,null(空值):不展示", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "_show_info", value = "是否展示详情", defaultValue = "false", required = false, dataType = "boolean", paramType = "query"),

    })
    //endregion
    //region 请求 : putByPressureMonitorId
    @RequestMapping(value = "/pressure-monitors/{pressureMonitorId}/codes", method = RequestMethod.PUT)
    //endregion
    @Author
    public ResponseEntity<PressureMonitor_CodeGetModel> putByPressureMonitorId(@PathVariable("iotDeviceId") Integer pressureMonitorId,
                                                                         @RequestParam @ApiIgnore Map<String, Object> query,
                                                                         @RequestBody PressureMonitor_CodePutModel body) throws ServiceException {
        PressureMonitor_CodeGetModel responseBody = pressureMonitor_codeService.putByPressureMonitorId(initHeader(), pressureMonitorId, query, body);
        return new ResponseEntity<>(responseBody, HttpStatus.OK);
        //endregion
    }
    //endregion
}

















































































































































































































































































































































































































































































































































































































































































